#include <climits>
#include <string>
#include <unordered_map>
using namespace std;
string minWindow(string s, string t) {
  // 1 统计t中元素出现频率
  unordered_map<char, int> t_map;
  for (int i = 0; i < t.size(); ++i) {
    t_map[t[i]]++;
  }
  int t_count = t_map.size();
  // 2 统计滑动窗口中字符出现次数
  int s_count = 0;
  unordered_map<char, int> s_map;
  int left = 0, right = 0;
  int resStart = 0, resLen = INT_MAX;
  while (right < s.size()) {
    if (t_map.count(s[right]) != 0) {
      s_map[s[right]]++;
      if (s_map[s[right]] == t_map[s[right]]) {
        s_count++;
      }
    }
    while (s_count == t_count) {
      if (right - left + 1 < resLen) {
        resLen = right - left + 1;
        resStart = left;
      }
      // 移动窗口左边界
      if (t_map.count(s[left])) {
        s_map[s[left]]--;
        if (s_map[s[left]] < t_map[s[left]]) {
          s_count--;
        }
      }
      left++;
    }
    right++;
  }
  if (resLen == INT_MAX)
    return "";
  return s.substr(resStart, resLen);
}